package course;
import java.awt.print.PrinterJob;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class method {
     public static boolean Connection(String sq) {
    	 PrinterJob out = PrinterJob.getPrinterJob();
    	 Connection con = null;
    	 Statement sql;
    	 ResultSet rs;
    	 try{
    	 Class.forName("com.mysql.cj.jdbc.Driver");
    	 }
    	 catch(Exception e){
    	 System.out.print("<h1>"+e);
    	 }
    	 String url = "jdbc:mysql://localhost:3306/course?"+
    	 "useSSL=false&serverTimezone=GMT&characterEncoding=utf-8";
    	 String user = "root";
    	 String password = "123456";
    	 try{
        	 con=DriverManager.getConnection(url,user,password);
        	 sql = con.createStatement();
        	 String SQL=sq;	

        	 sql.executeUpdate(SQL);
        	
        	 con.close();
        	 return true;
        	 }
        	 catch(SQLException e){
        	 System.out.print("<h1>"+e);
        	 return false;
        	 }         
     }
     public static ResultSet Search(String sq) {
    	 PrinterJob out = PrinterJob.getPrinterJob();
    	 Connection con = null;
    	 Statement sql;
    	 ResultSet rs = null;
    	 try{
    	 Class.forName("com.mysql.cj.jdbc.Driver");
    	 }
    	 catch(Exception e){
    	 System.out.print("<h1>"+e);
    	 }
    	 String url = "jdbc:mysql://localhost:3306/course?"+
    	 "useSSL=false&serverTimezone=GMT&characterEncoding=utf-8";
    	 String user = "root";
    	 String password = "123456";
    	 try{
        	 con=DriverManager.getConnection(url,user,password);
        	 sql = con.createStatement();
        	 String SQL=sq;	
        	 rs= sql.executeQuery(SQL);
        	 con.close();
        	 return rs;
        	 }
        	 catch(SQLException e){
        	 System.out.print("<h1>"+e);
        	 return rs;
        	 }         
     }
     
}
